﻿using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Xml.Serialization;

namespace TTApp.Phone.Silverlight.Hexagons.Code
{
    public class Settings
    {
        #region //--------- Private Fields --------------//
        private const string FileName = "settings.xml";
        private Gameplay _gameplay;
        private static IsolatedStorageSettings _isoSettings = IsolatedStorageSettings.ApplicationSettings;
        #endregion

        #region //--------- Public Methods --------------//
        public void Save()
        {
            //IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            //IsolatedStorageFileStream stream = storage.CreateFile(FileName);

            //XmlSerializer xml = new XmlSerializer(typeof(Settings));
            //xml.Serialize(stream, this);

            //stream.Close();
            //stream.Dispose();

            _isoSettings["gameplay"] = _gameplay;
        }

        #endregion

        #region //--------- Static Methods --------------//
        public static Settings Load()
        {
            //IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            //Settings settings;

            //if (storage.FileExists(FileName))
            //{
            //    IsolatedStorageFileStream stream = storage.OpenFile(FileName, FileMode.Open);
            //    XmlSerializer xml = new XmlSerializer(typeof(Settings));

            //    settings = xml.Deserialize(stream) as Settings;

            //    stream.Close();
            //    stream.Dispose();
            //}
            //else
            //{
            //    settings = new Settings();
            //}

            //return settings;


            Settings settings = new Settings();
            if (_isoSettings.Contains("gameplay"))
            {
                settings.Gameplay = _isoSettings["gameplay"] as Gameplay;
            }

            return settings;
        }
        #endregion

        #region //--------- CLR Properties --------------//
        /// <summary>
        /// Gets or sets the gameplay.
        /// </summary>
        /// <value>The gameplay.</value>
        public Gameplay Gameplay
        {
            get
            {
                return _gameplay;
            }
            set
            {
                _gameplay = value;
            }
        }
        #endregion
    }
}
